<template>
	<view class="">
		{{latLon}}<br />
		{{address.address}}<br />
	</view>
</template>

<script>
	export default {
		data(){
			return { 
				latLon:{},
				address:{}
			}
		},
		onShow() {
			// #ifdef H5
			navigator.geolocation.getCurrentPosition((res) => {
				this.latLon = {
					"latitude": res.coords.latitude,
					"longitude": res.coords.longitude,
				}
				this.getCity()
			}, function(error) {
				uni.showToast({
					title: '加载失败,请刷新重试',
					icon: "none"
				})
			});
			// uni.getLocation({
			// 	type: 'gcj02',
			// 	highAccuracyExpireTime: 100,
			// 	success: (res) => {
			// 		console.log(res, '----------------------res1')
			// 		this.latLon = {
			// 			"latitude": res.latitude,
			// 			"longitude": res.longitude,
			// 		}
			// 		this.getCity()
			// 	},
			// 	fail: (err) => {
			// 		uni.showToast({
			// 			title: '加载失败,请刷新重试',
			// 			icon: "none"
			// 		})
			// 	}
			// })
			// #endif
		},
		methods:{
			getCity() {
				let that = this;
				let locationType = '';
				if (uni.getSystemInfoSync().platform == 'android') { //android终端
					locationType = 'gcj02'
				} else if (uni.getSystemInfoSync().platform == "ios") { //ios终端
					locationType = 'wgs84'
				}
				// #ifdef H5
				uni.showLoading({
					title: '加载中..',
					duration: 1000
				})
				// let latLon = JSON.parse(uni.getStorageSync('latLon'))
				let latLon = this.latLon;
				let url = `https://apis.map.qq.com/ws/geocoder/v1/?location=`
				this.$jsonp(url, {
					key: 'QB3BZ-OTMRD-VTN4B-HOE6U-7IOZ6-AVFX4',
					location: `${latLon.latitude},${latLon.longitude}`,
					output: 'jsonp'
				}).then(res => {
					console.log(res, '-------------------------res2')
					console.log(`${latLon.latitude},${latLon.longitude}`, '------------当前经纬度')
					// uni.showModal({
					// 	title:'',
					// 	content:res.result.address
					// })
					if (res.status == 0) {
						setTimeout(() => {
							this.address = res.result
						}, 1000)
			
					}
					uni.hideLoading()
				})
				// #endif
			},
		}
	}
</script>

<style>
</style>